package com.film.controller;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.film.domain.Film;
import com.film.domain.FilmType;
import com.film.service.FilmService;
import com.film.service.FilmTypeService;
import com.film.service.impl.FilmServiceImpl;
import com.film.service.impl.FilmTypeServiceImpl;
/**
 * 该控制类用来做所有的商品展示
 * @author 2119196781
 *
 */
@WebServlet("/selectAll.do")
public class FilmController extends HttpServlet{
	private FilmService filmService = new FilmServiceImpl();
	private FilmTypeService filmTypeService = new FilmTypeServiceImpl();
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//查询所有的热播电影
		List<Film> films = filmService.selectAllFilm();	
		List<FilmType> types = filmTypeService.selectAllFilmType();
		//查询所有电影产地
		Set<String > placeSet = new HashSet<>();
		List<String> places = filmService.selectFilmPlace();
		for(String place:places) {
			String[] strs = place.split(",");
			for(String str:strs) {
				placeSet.add(str);
			}
		}
		request.getSession().setAttribute("types", types);
		request.getSession().setAttribute("films", films);
		request.getSession().setAttribute("places", placeSet);
		request.getSession().setAttribute("filmSize", films.size());
		response.sendRedirect("showFilm.jsp?flag1=-1&flag2=-1&flag3=-1&flage=2&flag4=-1&flag=1");
	}

	
}
